<?php
header('Content-type:text/html;charset=UTF-8');
require '../include/common.inc.php';
include_once('../include/api.class.php');
$res = json_decode($_POST['params']);
//如果参数是非json，返回错误
if($res == false)
{
	echo '参数错误';exit;
}
$action = isset($_GET['action']) ? $_GET['action'] : '';
switch ($action)
{
	case 'enroll':
		if(sizeof($res) != 3)
		{
			echo '参数错误'; exit;
		}
		$starttime = $res[0];
		$endtime = $res[1];
		$school = $res[2];
		$api = new schoolApi();
		$res = $api->school_get_enroll($starttime,$endtime,$school);
		echo serialize($res);exit;
		break;
	case 'complaint':
		if(sizeof($res) != 3)
		{
			echo '参数错误'; exit;
		}
		$starttime = $res[0];
		$endtime = $res[1];
		$school = $res[2];
		$api = new schoolApi();
		$res = $api->school_get_complaint($starttime,$endtime,$school);
		echo serialize($res);exit;
		break;
	default:
		if(sizeof($res) != 4)
		{
			echo '参数错误'; exit;
		}
		$catcode = $res[0];
		$siteid = $res[1];
		$school = $res[2];
		$contents = $res[3];
		$api = new schoolApi();
		$s_catcode = $api->get_s_code();
		if(!in_array($catcode, $s_catcode))
		{
			$res = $api->add_cat_content($contents,$siteid,$catcode,$school);
		}
		else 
		{
			$func = 'add_'.$catcode;
			$res = $api->$func($contents,$siteid,$school);
		}
		if($res === false)
		{
			echo '同步失败，请重新同步'; exit;
		}
		else 
		{
			echo 1; exit;
		}
		
}

?>